package com.hmy.contract.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmy.ccp.common.response.BasePageResponse;
import com.hmy.ccp.common.result.JsonResult;
import com.hmy.ccp.error.annotations.HmyGateWayController;
import com.hmy.contract.bo.request.contract.*;
import com.hmy.contract.bo.response.contract.*;
import com.hmy.contract.service.contract.IContractApprovalService;
import com.hmy.contract.service.contract.IContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @description 合同管理-新
 * @author seven.qi
 * @date 2023/12/19 19:32
 * @version 1.0
 */

@RestController
@RequestMapping("/api/contract")
@Validated
@HmyGateWayController
@Api(tags = "合同管理-新")
@Slf4j
public class ContractController {

    @Resource
    private IContractService contractService;

    @Resource
    private IContractApprovalService contractApprovalService;

    /**
     * 根据合同id查询合同详情
     *
     * @param contractInfoRequest 根据合同id查询合同详情入参
     * @return {@link ContractInfoResponse}
     */
    @GetMapping("contractInfo")
    @ApiOperation("根据合同id查询合同详情")
    public JsonResult<ContractInfoResponse> contractInfo(@Validated ContractInfoRequest contractInfoRequest) {
        return JsonResult.success(contractService.contractInfo(contractInfoRequest));
    }

    /**
     * 创建合同
     *
     * @param createContractRequest 创建合同入参
     * @return {@link CreateLeaseContractResponse}
     */
    @PostMapping("create")
    @ApiOperation("创建合同")
    public JsonResult<CreateLeaseContractResponse> create(@Validated @RequestBody CreateLeaseContractRequest createContractRequest) {
        return JsonResult.success(contractService.createLeaseContract(createContractRequest));
    }


    /**
     * 更新合同文件
     *
     * @param updateFileUrlRequest 更新合同文件入参
     * @return {@link UpdateFileUrlResponse}
     */
    @PostMapping("updateFileUrl")
    @ApiOperation("更新合同文件")
    public JsonResult<UpdateFileUrlResponse> updateFileUrl(@Validated @RequestBody UpdateFileUrlRequest updateFileUrlRequest) {
        return JsonResult.success(contractService.updateFileUrl(updateFileUrlRequest));
    }

    /**
     * 获取签署地址
     *
     * @param getSignUrlRequest 获取签署地址入参
     * @return {@link GetSignUrlResponse}
     */
    @GetMapping("getSignUrl")
    @ApiOperation("获取签署地址")
    public JsonResult<GetSignUrlResponse> getSignUrl(@Validated GetSignUrlRequest getSignUrlRequest) {
        return JsonResult.success(contractService.getSignUrl(getSignUrlRequest));
    }

    /**
     * 分页查询合同列表
     *
     * @param contractPageRequest 分页查询合同列表入参
     * @return {@link Page<ContractPageResponse>}
     */
    @GetMapping("page")
    @ApiOperation("分页查询合同列表")
    public JsonResult<BasePageResponse<ContractPageResponse>> page(ContractPageRequest contractPageRequest) {
        return JsonResult.success(contractService.page(contractPageRequest));
    }

    /**
     * 获取合同审批历史
     * @param contractApprovalHistoryRequest 获取增补合同审批历史入参
     * @return {@link JsonResult<ContractApprovalHistoryResponse>}
     */
    @GetMapping("contractApprovalHistory")
    public JsonResult<ContractApprovalHistoryResponse> getContractApprovalHistory(ContractApprovalHistoryRequest contractApprovalHistoryRequest){
        ContractApprovalHistoryResponse contractApprovalHistory = contractApprovalService.getContractApprovalHistory(contractApprovalHistoryRequest);
        return JsonResult.success(contractApprovalHistory);
    }

    /**
     * 风控部长审批合同
     * @param riskMinisterApprovalContractRequest 风控部长审批合同入参
     * @return {@link JsonResult<RiskMinisterApprovalContractResponse>}
     */
    @PostMapping("riskMinisterApprovalContract")
    public JsonResult<RiskMinisterApprovalContractResponse> riskMinisterApprovalContract(@RequestBody RiskMinisterApprovalContractRequest riskMinisterApprovalContractRequest){
        RiskMinisterApprovalContractResponse riskMinisterApprovalContract = contractApprovalService.riskMinisterApprovalContract(riskMinisterApprovalContractRequest);
        return JsonResult.success(riskMinisterApprovalContract);
    }

    /**
     * 区域经理审批合同
     * @param areaManagerApprovalContractRequest 区域经理审批合同入参
     * @return {@link JsonResult<AreaManagerApprovalContractResponse>}
     */
    @PostMapping("areaManagerApprovalContract")
    public JsonResult<AreaManagerApprovalContractResponse> areaManagerApprovalContract(@RequestBody AreaManagerApprovalContractRequest areaManagerApprovalContractRequest){
        AreaManagerApprovalContractResponse areaManagerApprovalContract = contractApprovalService.areaManagerApprovalContract(areaManagerApprovalContractRequest);
        return JsonResult.success(areaManagerApprovalContract);
    }
    /**
     * pc端-设备报停-查询列表-根据合同名称模糊 业务类型查询合同列表
     *
     * @param request
     * @return
     */
    @PostMapping("/pageQueryContract")
    public JsonResult<BasePageResponse<ContractQueryListResponse>> pageQueryContract(@RequestBody ContractQueryListRequest request) {
        return JsonResult.success(contractService.pageQueryContract(request));
    }

    /**
     * 根据关联系统id查询合同信息
     * @param request 请求参数
     * @return 返回结果 {@link GetContractInfoByRelationIdResponse}
     */
    @PostMapping("getContractInfoByRelationId")
    public JsonResult<GetContractInfoByRelationIdResponse> getContractInfoByRelationId(@RequestBody GetContractInfoByRelationIdRequest request) {
        return JsonResult.success(contractService.getContractInfoByRelationId(request));
    }

}
